<?php
/*  index.php

Copyright (C) 2011  Anthony Gaudino

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

include_once('config/settings.php');
include_once('includes/database/database_pool.inc');
include_once('includes/database/queries.inc');

include_once('includes/messages/error_message.inc');

$databse_connection = new database_pool();
$databse_connection -> connect($databases['driver'], $databases['database'],
        $databases['username'], $databases['password'], $databases['host'],
        $databases['port'], $databases['collation']);

if (!$is_database_configured)
{
    /*$databse_connection->execute_query($create_users_table);
    $databse_connection->execute_query($create_posts_table);
    $databse_connection->execute_query($create_forums_table);

    $is_database_configured = true;
    file_search_replace('config/settings.php', '$is_database_configured = false;', '$is_database_configured = true;');
    chmod('config/settings.php', 644);
    */
    
    if ($databse_connection -> get_last_error() == null)
    {
        include_once('includes/messages/install_success_message.inc');
    }
    else
    {
        show_error_message($databse_connection -> get_last_error());
    }
}
else
{
    
}

function file_search_replace($file, $old_string, $new_string)
{
    $content = file_get_contents($file);
    $content = str_replace($old_string, $new_string, $content);
    file_put_contents($file, $content);
}

//include_once('include/blocks/header.inc');
//include_once('include/blocks/body.inc');
//include_once('include/blocks/footer.inc');
//include_once('themes/' . $theme . '/template.php');

?>